using System.Collections.Generic;
using System.Runtime.CompilerServices;

namespace BepuUtilities.Collections
{
    /// <summary>
    /// IPredicate包装在EqualityCompeller和要进行比较的对象周围。
    /// </summary>
    /// <typeparam name="T">要比较的对象的类型。</typeparam>
    public struct WrapperPredicate<T> : IPredicate<T>
    {
        public T Item;
        public EqualityComparer<T> Comparer;
        /// <summary>
        /// 为给定类型创建默认比较器。
        /// </summary>
        /// <param name="Item">要与其他项目进行比较的项目。</param>
        /// <param name="谓词">使用此类型的默认比较器对其他项进行测试的谓词。</param>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static void CreateDefault(ref T item, out WrapperPredicate<T> predicate)
        {
            predicate.Item = item;
            predicate.Comparer = EqualityComparer<T>.Default;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public bool Matches(ref T otherItem)
        {
            return Comparer.Equals(Item, otherItem);
        }
    }


}
